#ifndef __AI_BASEINTERFACE_H_
#define __AI_BASEINTERFACE_H_

#include "Common.h"
#include "Resource.h"
#include "Threading/Mutex.h"
#include "ScriptMgr.h"
#include "Game.h"
#include "GameStruct.h"
#include "CenterBattleLogManager.h"
#include "MJEnum.h"
#include "PKEnum.h"
#include "PKStruct.h"
#include "GameDefine.h"
struct VIPCard;

class MJGameLogic;
class PKGameLogic;
class CChiHuRight;
class MJBaseTablePlayer;
class PKBaseTablePlayer;
namespace AIScript {
	class AIChannelBaseInterface;
	class AITownBaseInterface;
	class AITownVIPInterface;
	class AITownMarchInterface;
	class AICreatureBaseInterface;
	class AIEffectInterface;
	class AIMissionInterface;


#define TO_CHANNEL_BASE_INTERFACE(ptr) dynamic_cast<AIChannelBaseInterface *>(ptr)
#define TO_TOWN_BASE_INTERFACE(ptr) dynamic_cast<AITownBaseInterface *>(ptr) 
#define TO_TOWN_VIP_INTERFACE(ptr) dynamic_cast<AITownVIPInterface *>(ptr) 
#define TO_TOWN_MARCH_INTERFACE(ptr) dynamic_cast<AITownMarchInterface *>(ptr) 
#define TO_CREATURE_BASE_INTERFACE(ptr) dynamic_cast<AICreatureBaseInterface *>(ptr) 
#define TO_EFFECT_INTERFACE(ptr) dynamic_cast<AIEffectInterface *>(ptr)
#define TO_MISSION_INTERFACE(ptr) dynamic_cast<AIMissionInterface *>(ptr)	



	/** 牌桌基类 **/
	class SERVER_DECL AIChannelBaseInterface : public AIInterface
	{
	public:
		ADD_INTERFACE_FACTORY_FUNCTION(AIChannelBaseInterface);

		AIChannelBaseInterface(Resource * pUnit);
		virtual ~AIChannelBaseInterface(void) {};
	public:
		virtual void BroadcastPacket(WorldPacket *packet, bool isLock = true) {};
		virtual bool UseItem(CharPtr & pChr,
			const uint32 & model_id,
			const uint32 & data1,
			const uint32 & data2,
			const uint32 & data3)
		{
			return false;
		}
		virtual bool AwardHongBao(CharPtr &pChr, const uint32 &hbNum) { return true; }

		virtual bool Pause();								// 暂停游戏
		virtual bool CancelPause();							// 取消暂停
		virtual bool GetPauseStatus() { return m_bPause; } 	// 获得暂停标志

		virtual bool KickPlayer(const uint32 char_id);		// 踢出某个玩家
		virtual bool DissolveChannel() { return true; }		// 房主发起解散牌桌

		virtual uint32 GetMaxPlayerNum();					// 获得开桌的最大玩家数量（例如血战是4人）
		
		virtual bool JoinChannel(CharPtr & pChr, bool bSendJoinTown = true);										// 玩家加入牌桌
		virtual bool ExitChannel(CharPtr & pChr, bool bOffline = false, bool bLock = true){ return  false; }		// 退出战场
		
		// 同意或拒绝游戏（成功广播结果 失败单发结果 ）
		virtual bool AgreeOrRefusePlayGame(CharPtr & pChr, const uint8 & agree) { return true; }

		virtual std::vector<ResourceProxy> GetPlayers() { return m_vPlayers; }	// 返回座位上玩家数据

		virtual void PlayerChooseASeat(CharPtr & pChr, const uint8 & seat) {};				// 玩家选择座位
		virtual bool PlayerSendVote(CharPtr & pChr) { return true; }						// 玩家发起投票
		virtual bool PlayerDealVote(CharPtr & pChr, const uint8 & mode) { return true; }	// 玩家处理投票

		virtual uint8 GiveFreeGift(CharPtr & pChr, const uint32 & char_id, const uint8 & gift_id) { return 1; }	// 赠送免费道具
		
		virtual void SendSomeChannelInfo(){}							// 发送一些牌桌相关信息
		
		virtual void ClubBattleTimesUp(){}								// 俱乐部组局超时（没开始的牌局解释，开始的牌局，在下一轮的时候结束）
		
		virtual uint8 ClubManagerTuiFen(CharPtr & pChr){ return 1; }				// 俱乐部管理员退分
		
		// 充值时 更新玩家在牌桌中的数据
		virtual void UpdatePlayerDataWhenBuyGoods(CharPtr & pChr, const uint32 & before_changeNum){}
	public:

		std::vector<ResourceProxy> m_vPlayers;	// 牌桌中座位上玩家列表
		bool m_bPause;							// 暂停标志
	};

#ifdef MJPUBLIC
	class AIMaJiangChannelBaseInterface;
#define TO_MJCHANNEL_INTERFACE(ptr) dynamic_cast<AIMaJiangChannelBaseInterface *>(ptr)	
	typedef void (AIChannelBaseInterface::*StateInit)(void);
	typedef HSMStateHandler(AIChannelBaseInterface::*StateUpdate)(void);
	typedef std::vector<MJBaseTablePlayer * >::iterator TablePlayerIter;
	/* 麻将牌桌基类 */
	class SERVER_DECL AIMaJiangChannelBaseInterface : public AIChannelBaseInterface
	{
	public:
#define WGS_MJCHANNEL_MUTEX_NAME mjchn_change_mutex
#define WGS_MJCHANNEL_MUTEX mutable boost::mutex WGS_MJCHANNEL_MUTEX_NAME;
#define WGS_MJCHANNEL_LOCK		boost::lock_guard<boost::mutex> wgsMJChnChangeMutexLock(WGS_MJCHANNEL_MUTEX_NAME);
		WGS_MJCHANNEL_MUTEX

#define WGS_MJCHANNEL_STATE_MUTEX_NAME mjchn_State_mutex
#define WGS_MJCHANNEL_STATE_MUTEX mutable boost::mutex WGS_MJCHANNEL_STATE_MUTEX_NAME;
#define WGS_MJCHANNEL_STATE_LOCK		boost::lock_guard<boost::mutex> wgsMJChnStateMutexLock(WGS_MJCHANNEL_STATE_MUTEX_NAME);
			WGS_MJCHANNEL_STATE_MUTEX


#define WGS_MJCHANNEL_VOTE_MUTEX_NAME mjchn_Vote_mutex
#define WGS_MJCHANNEL_VOTE_MUTEX mutable boost::mutex WGS_MJCHANNEL_VOTE_MUTEX_NAME;
#define WGS_MJCHANNEL_VOTE_LOCK		boost::lock_guard<boost::mutex> wgsMJChnVoteMutexLock(WGS_MJCHANNEL_VOTE_MUTEX_NAME);
			WGS_MJCHANNEL_VOTE_MUTEX
			// 牌桌状态
			enum MJChannelState
		{
			en_MJChannelState_Init = 0,				// 初始状态
			en_MJChannelState_Prep = 1, 			// 准备状态（处理玩家准备逻辑）
			en_MJChannelState_ChooseBanker = 2, 	// 定庄
			en_MJChannelState_SendCards = 3,		// 丢骰子发牌
			en_MJChannelState_SwapCards = 4,		// 换牌
			en_MJChannelState_ChooseQue = 5,		// 定缺
			en_MJChannelState_GiveCard = 6,			// 摸牌
			en_MJChannelState_CastCard = 7,			// 出牌
			en_MJChannelState_OperatorCard = 8,		// 操作牌（吃碰杠听胡过）
			en_MJChannelState_GameOverCalc = 9,		// 结算
			en_MJChannelState_Close = 10,			// 牌桌结束
			en_MJChannelState_Vote = 11,			// 投票状态
			en_MJChannelState_SameIP = 12,			// 同ip
			en_MJChannelState_SendCardsBuPai = 13,			// 起手补牌
			en_MJChannelState_GiveCardsBuPai = 14,			// 摸牌补牌

			en_MJChannelState_Custom = 100,			// 自定义
		};

		// 游戏玩法标志
		enum enPlayerMode
		{
			enPlayerMode_Normal = 1,		// 普通玩法
			enPlayerMode_Swap = 2,			// 换牌玩法
			enPlayerMode_Que = 4,			// 定缺玩法
		};

		ADD_INTERFACE_FACTORY_FUNCTION(AIMaJiangChannelBaseInterface);

		AIMaJiangChannelBaseInterface(Resource * pUnit);
		~AIMaJiangChannelBaseInterface();
		void Load();							// 加载函数
		virtual void initialize();						// 初始函数
		void Update(const uint32 & p_time);		// 帧循环
		void initCenterBattleInfo(void);		// 初始棋牌圈数据

		void CreateCards();						// 生成牌
		void ShuffleCards();					// 洗牌
		virtual void RepositionSink();			//复位牌桌

	public:
		virtual uint8 GiveFreeGift(CharPtr & pChr, const uint32 & char_id, const uint8 & gift_id); // 赠送免费道具


		// 广播消息到座位列表
		virtual void BroadcastPacketSeat(WorldPacket *packet);
		// 广播消息到观战列表（有些信息观战的不能看，所以要单独处理）
		virtual void BroadcastPacketWatch(WorldPacket *packet);
		// 广播消息到所有玩家列表
		virtual void BroadcastPacket(WorldPacket *packet, bool isLock = true);
		virtual void Broadcast(WorldPacket *packet, uint32 serial);
		virtual bool JoinChannel(CharPtr & pChr, bool bSendPacket = true);									// 进入战场
		virtual void ReturnRoom(MJBaseTablePlayer *pTp);													// 返回牌桌
		virtual bool ExitChannel(CharPtr & pChr, bool bOffline = false, bool bLock = true);					// 退出战场

		virtual uint32 GetMaxPlayerNum();												// 最大游戏人数
		virtual bool CheckGameStart();													// 检查游戏是否开始
		virtual bool CheckAllPlayerAgreePlayGame();										// 检查是否所有玩家都已经准备
		virtual bool AgreeOrRefusePlayGame(CharPtr & pChr, const uint8 & agree_mode);	// 同意或者拒绝进行游戏
		virtual bool DissolveChannel();													// 房主发起解散

		//------------投票相关---------------------
		uint32		  m_ui32LogStatusTime;

		//判断牌局是否结束
		virtual bool CheckCenterBattleOver();

		//让离线托管玩家站起
		virtual void StandUpPlayerGameOver();

		//================================游戏逻辑部分=================================================
		virtual void ChoosePlayerInitSwapCardsWithOneColor(uint8 nChangeCount);									// 选择玩家默认交换的牌（单花色）
		virtual bool PlayerChooseSwapCards(CharPtr & pChr, std::vector<uint16> cards);							// 玩家换牌
		virtual void AutoChooseSwapCards();																		// 系统帮玩家换牌（时间到）
		virtual void DealPlayerSwapCards();																		// 处理玩家换牌
		virtual bool CheckAllPlayerSwapCards();																	// 检测是否所有玩家都已换牌
		virtual MJBaseTablePlayer * GetTablePlayer(const uint32 & char_id);											// 获得玩家对象
		virtual MJBaseTablePlayer * GetTablePlayerByPos(const uint32 & pos_id);										// 获得玩家对象
		virtual MJBaseTablePlayer * GetWatchPlayer(const uint32 & char_id);											// 获得观战玩家对象
		virtual bool PlayerChooseQue(CharPtr & pChr, const uint8 & que_color);									// 玩家选择定缺
		virtual void SystemAutoChooseQueColor(MJBaseTablePlayer * tb);												// 系统自动定缺
		virtual void SendAllPlayersQueInfo();																	// 发送所有玩家定缺消息															
		virtual void SendProtocolToPlayer(WorldPacket * packet, MJBaseTablePlayer & tp);						    //发送协议给玩家
		virtual void SendProtocolToPlayer(WorldPacket * packet, MJBaseTablePlayer * tp);						    //发送协议给玩家
		virtual void SendProtocolToPlayer(WorldPacket * packet, const uint8 & _pos);						    //发送协议给玩家

		virtual bool IsAllPlayerTrusteeship();																	//是否所有玩家都进行托管

		virtual bool IsAllPlayerOperatorInOperatorState();														//是否所有可操作玩家都操作了

		virtual bool RemoveCard(const uint8 & ui8TargetPos, std::vector<uint8 > vecRemoveCards);				//移除手牌

		virtual void Wait(const uint32 & _ms);																	//等待

		virtual void ChoosePlayerInitQueColor();																//选择玩家默认缺花色

		virtual void DealDuiJuFei();																			//扣除对局费
		bool m_bDealDuiJuFei;																					//是否还需要扣过对局费


		int8 m_i8SwapCardsPosType;																			//换牌位置
		virtual void SwapCards();																			//换牌
		virtual void PlayerChooseSwapCardsType(CharPtr & pChr, const uint8 & ui8SwapPosType,bool bLock = true);				//玩家选择换牌模式

		//================================游戏逻辑部分=================================================

		//获取牌桌中总人数
		virtual uint8 GetNowPlayerNum();

	

		//游戏是否开始
		virtual bool IsGameStart(bool bLock = false);				

		//通知牌桌状态
		virtual void SendTableStatus(const uint32 & serial,bool bReconnection = false);

		//玩家加入牌桌需要发的基本协议
		virtual void SendTableBaseProtocol(CharPtr & pChr);

	

		//重连操作
		virtual void CustomOperateInRuturnRoom(MJBaseTablePlayer * pTp) {};

		//--------------------------重连函数----------------------------------
		virtual void  ReturnChooseBanker(MJBaseTablePlayer * pTp, uint32 ui32LeftTime);
		virtual void  ReturnSendCards(MJBaseTablePlayer * pTp, uint32 ui32LeftTime);
		virtual void  ReturnSwapCards(MJBaseTablePlayer * pTp, uint32 ui32LeftTime);
		virtual void  ReturnChooseQue(MJBaseTablePlayer * pTp, uint32 ui32LeftTime);
		virtual void  ReturnGiveCard(MJBaseTablePlayer * pTp, uint32 ui32LeftTime);
		virtual void  ReturnCastCard(MJBaseTablePlayer * pTp, uint32 ui32LeftTime);
		virtual void  ReturnOperateCard(MJBaseTablePlayer * pTp, uint32 ui32LeftTime);
		virtual void  ReturnCustomStatus(MJBaseTablePlayer * pTp, uint32 ui32LeftTime) {};
		//自定义状态下的重连通知
		virtual void  RuturnCustom(MJBaseTablePlayer* pTp, String  StatsKey, uint32 ui32LeftTime) {};
		//============================玩家列表操作相关（座位和观战）===================================
		virtual bool PlayerSit(CharPtr & pChr, const uint32 & seat_id, bool bLock = false);			// 玩家入座
		virtual bool PlayerStandUp(CharPtr & pChr,bool bLock = false);								// 玩家起立

		virtual bool PlayerSendVote(CharPtr & pChr);							// 玩家发起投票
		virtual bool PlayerDealVote(CharPtr & pChr, const uint8 & mode);		// 玩家处理投票
		virtual bool PlayerDealVoteLock(CharPtr & pChr, const uint8 & mode);		// 玩家处理投票

		// 玩家退出牌桌
		virtual void AllPlayersLeaveRoom();
		//============================玩家列表操作相关（座位和观战）===================================



	public:
		//===================================状态机相关================================================
		//战场状态相关
		WGSERVER_INLINE void setRunStatus(const MJChannelState & status) { m_run_status = status; }
		WGSERVER_INLINE MJChannelState GetRunStatus() { return m_run_status; }

		//状态结束时间相关
		virtual	WGSERVER_INLINE void setStatusEndTimer(const uint32 & timer) { m_status_endtimer = now() + timer; }
		virtual	WGSERVER_INLINE uint32 getStatusEndTimer() { return m_status_endtimer; }


		//切换战场状态
		HSMStateHandler	ChangeChannelState(MJChannelState state);

		//初始话自定义状态函数
		virtual void    InitPublicFun();			
	protected:
		String _StateKey;
		std::map<String, StateInit>  m_mapStateInit;
		std::map<String, StateUpdate>  m_mapStateUpdate;
	public:
		//设置状态
		void   SetChannelPublicFun(String _key);
		//切换状态
		void   ChangeChannelPublicFun();

		void        RunPublicBattelStateInit();
		StateInit   publicBattelStateInit;
		virtual void setChannelBattlePrep(void);												// 准备Init
		virtual void setChannelBattleChooseBanker(void);										// 定庄Init
		virtual void setChannelBattleSendCards(void);											// 发牌Init
		virtual void setChannelBattleSwapCards(void);											// 换牌Init
		virtual void setChannelBattleChooseQue(void);											// 定缺Init
		virtual void setChannelBattleGiveCard(void);											// 摸牌Init
		virtual void setChannelBattleCastCard(void);											// 出牌Init
		virtual void setChannelBattleOperatorCard(void);										// 操作牌Init
		virtual void setChannelBattleCalc(void);												// 结算Init
		virtual void setChannelBattleClose(void);												// 牌桌结束Init
		virtual void setChannelBattleSendCardsBuPai(void);										// 起手补牌Init
		virtual void setChannelBattleGiveCardBuPai(void);										// 摸牌补牌Init

		virtual void setChannelBattleSameIPCheck(void);											// 同ip检测Init


		HSMStateHandler  RunPublicBattelUpdate(void);
		StateUpdate   publicBattelUpdate;
		virtual HSMStateHandler	ChannelBattlePrepUpdate(void);									// 准备Update
		virtual HSMStateHandler	ChannelBattleChooseBankerUpdate(void);							// 定庄Update
		virtual HSMStateHandler	ChannelBattleSendCardsUpdate(void);								// 发牌Update
		virtual HSMStateHandler	ChannelBattleSwapCardsUpdate(void);								// 换牌Update
		virtual HSMStateHandler	ChannelBattleChooseQueUpdate(void);								// 定缺Update
		virtual HSMStateHandler	ChannelBattleGiveCardUpdate(void);								// 摸牌Update
		virtual HSMStateHandler	ChannelBattleCastCardUpdate(void);								// 出牌Update
		virtual HSMStateHandler	ChannelBattleOperatorCardUpdate(void);							// 操作牌Update
		virtual HSMStateHandler	ChannelBattleCalcUpdate(void);									// 结算Update
		virtual HSMStateHandler	ChannelBattleSendCardsBuPaiUpdate(void);						// 起手补牌Update
		virtual HSMStateHandler	ChannelBattleGiveCardsBuPaiUpdate(void);						// 摸牌补牌Update

		virtual HSMStateHandler	ChannelBattleSameIPCheckUpdate(void);									// 同ip检测 Update

	protected:
		static HSMState battle_init(AIMaJiangChannelBaseInterface *me, HSMEvent const *e);		// 初始状态
		static HSMState battle_prep(AIMaJiangChannelBaseInterface *me, HSMEvent const *e);		// 准备状态
		static HSMState battle_choosebanker(AIMaJiangChannelBaseInterface *me, HSMEvent const *e);	// 定庄状态
		static HSMState battle_sendcards(AIMaJiangChannelBaseInterface *me, HSMEvent const *e);	// 发牌状态
		static HSMState battle_swapcards(AIMaJiangChannelBaseInterface *me, HSMEvent const *e);	// 换牌状态
		static HSMState battle_chooseque(AIMaJiangChannelBaseInterface *me, HSMEvent const *e);	// 定缺状态
		static HSMState battle_givecard(AIMaJiangChannelBaseInterface *me, HSMEvent const *e);	// 摸牌状态
		static HSMState battle_castcard(AIMaJiangChannelBaseInterface *me, HSMEvent const *e);		// 出牌状态
		static HSMState battle_operatorcard(AIMaJiangChannelBaseInterface *me, HSMEvent const *e);	// 操作牌状态
		static HSMState battle_calc(AIMaJiangChannelBaseInterface *me, HSMEvent const *e);			// 结算状态
		static HSMState battle_close(AIMaJiangChannelBaseInterface *me, HSMEvent const *e);			// 牌桌结束状态
		static HSMState battle_custom(AIMaJiangChannelBaseInterface *me, HSMEvent const *e);			// 牌桌自定义状态
		static HSMState battle_sendcardsbupai(AIMaJiangChannelBaseInterface *me, HSMEvent const *e);			// 起手补牌状态状态
		static HSMState battle_gviecardsbupai(AIMaJiangChannelBaseInterface *me, HSMEvent const *e);			// 起手补牌状态状态

		static HSMState battle_sameipcheck(AIMaJiangChannelBaseInterface *me, HSMEvent const *e);			// 牌桌同ip检测


		//===================================状态机相关================================================

	protected:


		//=================================麻将逻辑

		//初始化GameLogic
		virtual void InitGameLogic();

		MJGameLogic* m_GameLogic;

		//================================定庄相关函数

		//随机产生庄家
		virtual void   MakeRandBanker();

		//================================发牌相关函数

		uint8 m_ui8StartTestCardsIndex;										//配牌发牌器初始下标

		//游戏每局开始时发初始手牌   参数为发牌数量
		virtual void  DistributeInitalHandCards(const uint8 & ui8CardNum);

		//配牌
		virtual void  TestHandCards();

		virtual void SendMagicCardList() {};

		//发送手牌列表
		virtual void  SendHandCards(const uint8 & ui8PlayerPosID,const uint8 & type, bool bReconnection = false);


		//发牌
		virtual bool DispatchCardData(const uint8 & ui8PlayerPosID, bool isTail = false);

		//补牌
		virtual uint8 CompensateCard(const uint8 & ui8PlayerPosID, std::vector<uint8>  vecCardList);

		//是否是花牌
		virtual bool IsHuaPai(const uint8 & ui8CardData);

		//处理花牌
		virtual uint8 DealHuaPai(const uint8 ui8PlayerPosID,const uint8 & ui8CardData);
		
		//起手补花
		virtual void GameStartBuHua();

		std::vector<uint8> m_vecStartBuPaiStatus;

		//听牌
		virtual uint8 AnalyseTingCard(std::vector<uint8> vecCardIndex, std::vector<tagWeaveItem > & vecWeave, std::map<uint8, std::vector<uint8> > & mapTingPaiList);
		virtual uint8 AnalyseTingCard(const uint8 & ui8PlayerPosID);

		//玩家操作
		virtual bool UserOperateCard(const uint8 & ui8PlayerPosID, const uint8 & ui8OperateCard, const uint8 & ui8OperateCode, std::vector<uint8 > ui8CardData);
	public:
		virtual bool UserOperateCard(CharPtr & pChr, const uint8 & ui8OperateCard, const uint8 & ui8OperateCode, std::vector<uint8 > ui8CardData);
	protected:
		//摸牌者杠牌
		virtual void SelfGang(const uint8 & ui8PlayerPosID, const uint8 & ui8OperatorCard, std::vector<uint8 > ui8CardData, bool bQiangGang);

		//出牌响应
		virtual bool  EstimateUserRespond(const uint8 & ui8CurrentPos, const uint8 & ui8CenterCard, const uint8 & EstimatKind);

		virtual bool  IsEstimateChi(const uint8 & ui8CurrentPos, const uint8 & ui8EstimatePos, const uint8 & ui8CenterCard) { return true; };
		virtual bool  IsEstimatePeng(const uint8 & ui8CurrentPos, const uint8 & ui8EstimatePos, const uint8 & ui8CenterCard) { return true; };
		virtual bool  IsEstimateGang(const uint8 & ui8CurrentPos, const uint8 & ui8EstimatePos, const uint8 & ui8CenterCard) { return true; };
		virtual bool  IsEstimateTing(const uint8 & ui8CurrentPos, const uint8 & ui8CenterCard) { return true; };
		virtual bool  IsEstimateHu(const uint8 & ui8CurrentPos, const uint8 & ui8EstimatePos, const uint8 & ui8CenterCard) { return true; };
		virtual bool  IsEstimateYiPaoDuoXiang() { return true; };

		//听牌下的杠牌
		virtual bool TingEstimateGang(const uint8 & ui8CurrentPos, const uint8 & ui8CenterCard);

		//发送操作通知
		virtual void  SendOperateNotify();
		//================================操作牌相关函数

		//根据动作类型移除手牌
		std::vector<uint8> RemoveCardByAction(const uint8 & ui8TargetPos, const uint8 & ui8Action, const uint8 & ui8TargetCard);

		//获取两个座位的位置关系
		virtual uint8	GetRelativePos(const uint8 & ui8PlayerPos, const uint8 & ui8TargetPos);	


		//动作优先级
		virtual uint8	GetUserActionRank(uint8 ui8UserAction, uint8 ui8CurrentPos,uint8 ui8TargetPos,uint8 ui8ProvidePos, std::vector<uint8 > ui8CardData);

		virtual void OperateChi(uint8 ui8CurrentPos, tagWeaveItem & _weaveItem) {};
		virtual void OperatePeng(uint8 ui8CurrentPos, tagWeaveItem & _weaveItem) {};
		virtual void OperateGang(uint8 ui8CurrentPos, tagWeaveItem & _weaveItem) {};
		virtual void OperateHu(uint8 ui8CurrentPos, uint8 ui8ProvidePos, uint8  ui8CenterCard) {};
		virtual void OperateListen(const uint8 & ui8CurrentPos, const uint8 & ui8OperatorCard) {};
		virtual void OperateGuo(const uint8 & ui8CurrentPos, const uint8 & ui8OperatorCard,const uint8 ui8Action) {};
		//玩家出牌操作
		virtual void OperateOutCard(const uint8 & ui8CurrentPos, const uint8 & ui8OperatorCard) {};
		//玩家出牌操作
		virtual void OperateDispatchCardData(const uint8 & ui8CurrentPos, const uint8 & ui8OperatorCard) {};

		//抢杠响应
		virtual bool  EstimateUserQiangGang(const uint8 & ui8CurrentPos, const uint8 & ui8CenterCard);
		//玩家出牌
		virtual uint8 UserOutCard(const uint8 & ui8PlayerPosID, const uint8 & ui8OutCardData,bool bUser = false);

	
		
	public:
		virtual bool  UserOutCard(CharPtr pChr, const uint8 & ui8OutCardData);
	protected:

		//自动操作
		virtual void AutoOperate(uint8 ui8PlayerPosID);

		//自动出牌选择
		virtual uint8 AutoOutCardChoose(uint8 ui8PlayerPosID);

		//状态变动通知
		virtual void SendPlayerStatus(const uint8 & ui8PlayerPosID, const uint8 & ui8Status);
	public:
		//设置玩家状态
		virtual void SetPlayerStatus(CharPtr &pChr, const uint8 & playerStatus);
	protected:
		//胡牌判断  ui8CurrentCard  胡的牌    
		virtual uint8	AnalyseHuCard(const uint8 & ui8PlayerPosID, uint8 ui8CurrentCard, CChiHuRight &ChiHuRight);

		virtual uint8	AnalyseHuCard(std::vector<uint8>& ui8CardIndex, std::vector<tagWeaveItem> WeaveItem, uint8 ui8CurrentCard, CChiHuRight &ChiHuRight);
		virtual uint8	AnalyseHuCard(const uint8 & ui8PlayerPosID,std::vector<uint8>& ui8CardIndex, std::vector<tagWeaveItem> WeaveItem, uint8 ui8CurrentCard, CChiHuRight &ChiHuRight);

		virtual std::vector<uint8> GetTingPaiList(const uint8 & ui8PlayerPosID, const uint8 & ui8CenterCard);
		//==========================结算

		//结算前的操作
		virtual void  BeforeGameOverCalc();

		//检测游戏是否结算
		virtual bool CheckGameOverCalc();

		//发送胡牌情况  
		virtual void SendHuPaiInfo(uint8 ui8PlyaerChairID = 0);

		//发送亮牌协议
		virtual void SendLiangPaiInfo();

		//获取番型
		virtual uint32  GetHuPaiFanXing(const uint8 & ui8PlayerPosID);
		virtual uint32  GetHuPaiFanXing(CChiHuRight & chr);

		//获取胡牌附加数据
		virtual uint32  GetHuPaiExData(const uint8 & ui8PlayerPosID);
		virtual uint32  GetHuPaiExData(CChiHuRight & chr);
		//结算
		virtual void  settleAccounts();

		//棋牌圈每局处理
		virtual void  CenterBattleDeal();
		//棋牌圈数据
		virtual void AdditionalCBData();
		//服务器补充数据
		virtual void AdditionalGameServerCBData(Json::Value & val) {};

		//自定义json数据
		virtual void  CustomJsonData(MJBaseTablePlayer * pTp, Json::Value & val);

		//自定义json数据
		virtual void  CustomCenterDBJsonData(MJBaseTablePlayer * pTp, Json::Value & val) {};
		//流局判断
		virtual bool GameLoopOver();
		virtual bool IsLiuJu();
		virtual void DealLiuJu();

		//特殊胡牌模式
		virtual bool IsSpecialHu(const uint8 & ui8PlayerPos);

		//抢杠
		virtual bool IsQiangGang();
		virtual void DealQiangGang(const uint8 & ui8ProvidePos);

		//自摸
		virtual bool IsZiMo();
		virtual void DealZiMo(const uint8 & ui8CurrentPos);

		//岭上开花
		virtual bool IsLingShangKaiHua();
		virtual void DealLingShangKaiHua(const uint8 & ui8CurrentPos);

		//放炮
		virtual bool IsFangPao();
		virtual void DealFangPao(const uint8 & ui8ProvidePos);

		//追加处理
		virtual void AttachedAccounts();

		//局数变化统计
		uint8 m_ui8FengQuanLoopCount;

		//铜钱场追加处理
		virtual void DealTongQianChang();

		//回放记录
		virtual void PlayBack(WorldPacket * pPacket);

		//游戏开始数据
		virtual void LogGameStart();

		//记录玩家手牌
		virtual void LogPlayerHandCars();
	public:
		//==========================麻将相关数据=======================================================


		std::vector<uint8> m_dice;							// 骰子列表

		//uint8 m_curBankerPos;								// 当前庄家位置
		uint8 m_curStartPos;								// 最先开始打牌位置
		uint8 m_nGameModeFlag;								// 游戏玩法标志
		uint8 m_curOutCard;									// 玩家出牌
		uint8 m_curCastPos;									// 当前出牌玩家座位
		uint8 m_isHead;										// 是否从头摸牌
		uint32 m_tailCount;									// 从尾摸牌数量
		uint32 m_huNum;										// 可胡牌玩家数量
		uint8  m_ui8MaxHandCount;							// 最大手牌数量

		uint8 m_ui8LiuJuCardNum;							//流局牌数
	protected:
		uint8	m_ui8SiceCount;								//骰子点数
		uint8	m_ui8DongFengSeat;							//东风位
		uint8	m_ui8BankerPos;							//庄家用户
		uint8	m_ui8NextBankerPos;							//庄家用户
		std::vector<std::vector<uint8> >	m_ui8UserCardIndex;			//用户手牌
		std::vector<uint8>				m_ui8Trustee;					//玩家托管状态
		std::vector<uint8 >				m_bPlayStatus;					//玩家是否能进行游戏
		std::vector<uint8>			    m_bHasHuPai;		//玩家是胡牌

		std::vector<std::vector<uint8> >      m_vecLouHuCards;					//漏胡列表
		std::vector<std::vector<uint8> >      m_vecNoOutCardsIndex;					//不能出牌列表

																				//用户状态
	public:
		std::vector<uint8>				m_bResponse;							//响应标志
		std::vector<uint8>				m_ui8UserAction;						//用户动作
		std::vector<uint8>				m_ui8OperateCard;						//操作扑克
		std::vector<uint8>				m_ui8PerformAction;						//执行动作
		std::vector<uint8>				m_ui8LastAction;						//执行动作
		std::vector<std::vector<uint8> >	m_ui8TargetCardData;				//实际操作牌值

	protected:
		//---------状态变量
		bool							m_bSendStatus;							//发牌状态
		bool							m_bGangStatus;							//抢杆状态
		bool							m_bGangKai;								//岭上开花
		bool							m_bGangOutStatus;						//杠上炮
		bool							m_bBuPai;								//补牌
		uint8							m_ui8BuCard;							//补牌
		std::vector<uint8>				m_bEnjoinChiHu;							//禁止吃胡
		std::vector<uint8>				m_bEnjoinChiPeng;						//禁止吃碰
		std::vector<uint8>				m_bBaoJiao;								//报叫状态
		std::vector<uint8>				m_bGuoShui;								//过水不胡(震听状态)

																				//-----------发牌信息
	protected:
		uint8							m_uint8SendCardData;						//发牌扑克
		uint8							m_uint8SendCardCount;						//发牌数目
		uint16							m_uint8LeftCardCount;						//剩余数目
		uint8							m_uint8MaxCardNum;							//麻将最大牌数
		std::vector<uint8>				m_uint8RepertoryCard;						//库存扑克

																						//-----------牌墙变量
	protected:
		uint8							m_ui8HeapHand;							//堆立头部
		uint8							m_ui8HeapTail;							//堆立尾部
		std::vector<std::vector<uint8 > >			m_ui8HeapCardInfo;			//堆牌信息



																				//------- 出牌信息
	protected:
		uint8	m_ui8OutCardPos;							//出牌用户
		uint8	m_ui8OutCardData;							//出牌数据
		uint8	m_ui8OutCardCount;							//出牌数
		//std::vector<uint8>	m_ui8DiscardCount;				//弃牌数
		std::vector<std::vector<uint8> >	m_ui8DiscardCard;		//丢弃记录

		bool	m_bAnyOperate;								//是否操作
															//发牌信息
	protected:
		uint8	m_ui8ProvideCard;							//供应的扑克
		uint8	m_ui8ProvidePos;							//供应的用户
		uint8	m_ui8CurrentPos;							//当前操作的用户
		uint8	m_ui8ResumePos;							//还原用户
		uint8	m_ui8SendCardPos;							//当前
															//------------组合扑克
	protected:
		std::vector<std::vector<tagWeaveItem> >			m_WeaveItemArray;//组合扑克

																				 //---------------------结束信息																		 //结束信息
	protected:
		bool							m_bQiangGangHu;							//是否开启抢杠胡
		uint8							m_ui8QiangGangProvideCard;				//抢杠牌
		uint8							m_ui8QiangGangProvidePos;				//抢杠用户
		uint8							m_ui8AllPlayerOperatorStatus;					//一炮多响
		uint8							m_ui8ChiHuCard;							//吃胡扑克
		std::vector<uint32>				m_ui32ChiHuKind;						//吃胡结果
		std::vector<CChiHuRight>		m_ChiHuRight;							//得分统计

		std::vector<std::map<uint8, std::vector<uint8> > >						m_MPlayerTingCardList;		//玩家听牌列表
		std::vector<std::vector<std::vector<uint8> > >							m_VPlayerPengCardList;		//玩家碰牌列表
		std::vector<std::vector<std::vector<uint8> > >							m_VPlayerGangCardList;		//玩家杠牌列表
		std::vector<std::vector<std::vector<uint8> > >							m_VPlayerChiCardList;		//玩家吃牌列表


		std::vector<uint8>											m_ui8YiPaoDuoXiangList;	//一炮多响列表
		uint8							m_ui8GangPlayer;		//杠牌玩家
		uint8							m_ui8GangCard;			//杠牌中心牌
		std::vector<uint8>              m_ui8GangCardData;		//杠牌牌数据

		uint8							m_ui8MaPaiMode;			//买马模式
		uint8							m_ui8MaxMaPaiNum;							//最大马牌数量
		uint8							m_ui8MaPaiNum;							//马牌数量
		std::vector<uint8>				m_ui8MaPaiList;							//马牌列表

		std::vector<uint8>				m_ui8QueColor;							//缺色
		std::vector<std::vector<uint8> >				m_vecSwapCards;			//换牌列表
		std::vector<std::vector<uint8> >								m_ui8MagicCardsList;	//癞子牌列表
		std::vector<std::vector<uint8> >				m_ui8HuaPaiList;		//玩家花牌列表

		std::vector<std::vector<uint8> >				m_vecPlayerTingPaiTiShi;

		bool	m_bOutMagicCard;												//出牌作为癞子胡

		bool	m_bOutCardTingList;											//出牌听牌列表

		bool	m_bShowConstantlyCale;
		std::vector<MJConstantlyCale>					m_vecPlayerConstantlyCaleList;			//及时输赢


			//=============================================================================================

	public:
		//初始话玩家列表
		virtual void InitPlayerSeatList();
		std::vector<MJBaseTablePlayer *> m_vSeatPlayers;			// 座位玩家列表
		std::map<uint32, MJBaseTablePlayer> m_mapWatchPlayers;	// 观战玩家列表


		MJChannelState m_run_status;						// 当前运行状态
		MJChannelState m_next_run_status;					// 下个运行状态

		uint32 m_status_endtimer;							// 状态机结束时间
		uint32 m_status_starttimer;							// 状态机开始时间

		bool  m_bOverTimeWait;								//超时是否等待

		uint32 m_nGameAIType;								// 游戏AI类型
		uint32 m_nRoomType;									// 房间类型
		uint32 m_nMaxPlayerNum;								// 最大游戏人数
		uint32 m_nWarPlayerNum;								// 进行游戏的人数
		uint32 m_nStartPlayerNum;								// 开始游戏的人数

		uint32 m_nExit_coins;								//离场金币数

		uint32 m_nLoopId;									// 当前组局轮次

		uint32 m_nRoundId;									// 当前圈数轮次

		uint8 m_ui8RoundMode;								//游戏局数模式

		std::map<uint32, stVotePlayer> m_mapVotePlayers;	// 投票玩家列表
		bool m_bVoting;										// 投票中
		uint32 m_nVoteOverTime;								// 投票结束时间
		uint32 m_nNextCheckTimeoutTime;						// 检查牌桌超时的时间
		uint32 m_nTimeoutTimer;								// 检查牌桌超时的时间
		uint8 m_nDissolveReson;								// 解散原因


		bool m_bNormalExit;										// 是否正常退出（非正常退出返还开局费）
		bool m_bDissolve;										// 牌桌是否为解散
		bool m_bGameOver;										// 游戏结束
		bool m_bHaveSameIP;										// 是否有同IP玩家
		bool m_bThinkSameIP;									// 是否正在考虑同意同IP玩家
		bool m_bPreCalc;										// 上把结算
		bool m_bSameIPCheck;									//同ip检测
		uint8 m_ui8PayMode;										//付款模式



		bool m_bInitCenterData;								// 初始化组局数据
		uint32 m_nGameStartTime;							// 游戏开始时间
		uint32 m_nCreateTime;								// 牌桌创建时间
		uint32 m_nTingQianChangTimer;								// 牌桌创建时间

		uint32 m_nChooseBankerWaitTimer;					// 定庄等待时间
		uint32 m_nSendInitalCardsWaitTimer;					// 发牌等待时间
		uint32 m_nSwapCardsWaitTimer;						// 换牌等待时间
		uint32 m_nChooseQueWaitTimer;						// 定缺等待时间
		uint32 m_nSameIPCheckTimer;							//同IP检测时间

		uint32 m_nCastHandCardTime;							// 出牌牌等待时间
		uint32 m_nOperatorCardTime;							// 操作牌等待时间
		uint32 m_canWaitTime;								// 状态结束可等待时间

		uint32 m_nAGiveHandCardTime;						//摸牌动画时间
		uint32 m_nAHuPaiTime;								//胡牌动画时间

		uint32 m_nCB_id;									// 组局id
		BattleTotalLog m_btLog;								// 组局数据记录
		uint32 m_nTopTimes;									// 封顶倍数
		uint32 m_nFzPid;									// 组局房主PID
		uint32 m_nBasePoint;								// 底分
		uint32 m_nLimitLoop;								// 限制局数
		uint32 m_nLimitRound;								// 限制圈数
		uint32 m_nLimitTime;								// 限制时间
		uint32 m_nGameID;									// 组局游戏ID
		uint32 m_nGzid;										// 组局分区ID
		uint32 m_nMode;										// 游戏玩法ID
		String m_strPlayJsonData;							// 组局信息json字符串
		TownPtr m_Town;										// 牌桌对应房间
		Json::Value  m_GameLogData;							//游戏回放记录

		//========================对外接口=======================
	public:
		//获取手牌列表
		virtual std::map<uint32, uint32>     GetHandCards(uint8 pos);
		//获取吃碰杠列表
		virtual std::vector<tagWeaveItem>&   GetWeaveList(uint8 pos);
		//获取出牌列表
		virtual std::vector<uint32 >		 GetDiscardCardsList(uint8 pos);
		//获取可执行的操作
		virtual uint8						 GetAction(uint8 pos);
		//设置可执行动作
		virtual void						 SetAction(uint8 pos,const uint8 & ui32Action);
		//清空可执行动作
		virtual void						 CleanAction(uint8 pos);

		////获取胡牌信息
		//virtual HuInfo						 GetHuPaiXingxi(uint8 pos);

		//添加牌
		virtual void  AddCard(uint8 pos,const uint32 card, uint32 num = 1);
		//移除牌
		virtual void  RemoveCard(uint8 pos,const uint32 card, uint32 num = 1);
		//设置牌的张数
		virtual void  SetCardNum(uint8 pos,const uint32 card, uint32 num);
		//增加吃碰杠
		virtual void  AddChiPengGang(uint8 pos,tagWeaveItem & Weave);

		//检测是否可以胡牌
		virtual bool  CheckPlayerHuPai(uint8 pos);
		//检测是否可以听牌
		virtual bool  CheckPlayerTingPai(uint8 pos);
		//检测是否可以吃牌
		virtual bool  CheckPlayerChiPai(uint8 pos,uint32 card);
		//检测是否可以碰牌
		virtual bool  CheckPlayerPengPai(uint8 pos,uint32 card);
		//检测是否可以杠牌
		virtual bool  CheckPlayerGangPai(uint8 pos);
		//检测是否可以杠牌
		virtual bool  CheckPlayerGangPai(uint8 pos,uint32 card);
	};
#endif // MJPUBLIC
#ifdef PKPUBLIC
	class AIPuKeChannelBaseInterface;
#define TO_PKCHANNEL_INTERFACE(ptr) dynamic_cast<AIPuKeChannelBaseInterface *>(ptr)
	/* 扑克牌桌基类 */
	class SERVER_DECL AIPuKeChannelBaseInterface : public AIChannelBaseInterface
	{
	public:
	
#define WGS_PKCHANNEL_MUTEX_NAME mjchn_change_mutex
#define WGS_PKCHANNEL_MUTEX mutable boost::mutex WGS_PKCHANNEL_MUTEX_NAME;
#define WGS_PKCHANNEL_LOCK		boost::lock_guard<boost::mutex> wgsPKChnChangeMutexLock(WGS_PKCHANNEL_MUTEX_NAME);
		WGS_PKCHANNEL_MUTEX

#define WGS_PKCHANNEL_STATE_MUTEX_NAME mjchn_State_mutex
#define WGS_PKCHANNEL_STATE_MUTEX mutable boost::mutex WGS_PKCHANNEL_STATE_MUTEX_NAME;
#define WGS_PKCHANNEL_STATE_LOCK		boost::lock_guard<boost::mutex> wgsPKChnStateMutexLock(WGS_PKCHANNEL_STATE_MUTEX_NAME);
		WGS_PKCHANNEL_STATE_MUTEX
	
	public:
		enum PKChannelRunStatus
		{
			en_PKChannelRun_Init,							//无效状态
			en_PKChannelRun_PrepPlayer 			= 1,		//准备(玩家进入战场开桌判断）
			en_PKChannelRun_WillStart 			= 2,		//即将开始
			en_PKChannelRun_SendCards 			= 3,		//发牌
			en_PKChannelRun_CarryOn				= 4,		//游戏中(闷牌，下注，比牌）
			en_PKChannelRun_GetCards			= 5,		//摸牌
			en_PKChannelRun_OutCards			= 6,		//出牌
			en_PKChannelRun_GameCalc 			= 7,		//结算
			en_PKChannelRun_GameOver 			= 8,		//战场结束（所有玩家离开到战场删除）
			en_PKChannelRun_ShowMove 			= 9,		//动画表现状态
			en_PKChannelRun_SameIP 				= 10,		//同IP检测
			en_PKChannelRun_GetKing				= 11,		//抢地主
			en_PKChannelRun_AddMult 			= 12,		//加倍
		};
		
		ADD_INTERFACE_FACTORY_FUNCTION(AIPuKeChannelBaseInterface);
		
		AIPuKeChannelBaseInterface(Resource * pUnit);
		~AIPuKeChannelBaseInterface();
		void Load();							// 加载函数		
		void Update(const uint32 & p_time);		// 帧循环
		
	public:
		/*----------------------------- 一些底层接口的重载 ---------------------------------------*/
		virtual void Initialize();						// 初始函数
		virtual void InitCenterBattleInfo(void);		// 初始棋牌圈数据
		virtual uint32 GetMaxPlayerNum();				// 获得开桌的最大玩家数量（例如血战是4人）
		virtual bool JoinChannel(CharPtr & pChr, bool bSendJoinTown = true);										// 玩家加入牌桌
		virtual bool ExitChannel(CharPtr & pChr, bool bOffline = false, bool bLock = true);		// 退出战场
		virtual bool AgreeOrRefusePlayGame(CharPtr & pChr, const uint8 & agree);					// 同意或拒绝游戏（成功广播结果 失败单发结果 
		virtual bool PlayerSendVote(CharPtr & pChr);						// 玩家发起投票
		virtual bool PlayerDealVote(CharPtr & pChr, const uint8 & mode);	// 玩家处理投票
		virtual uint8 GiveFreeGift(CharPtr & pChr, const uint32 & char_id, const uint8 & gift_id);	// 赠送免费道具
		virtual bool ReturnRoom(PKBaseTablePlayer *pkPlayer);	// 玩家返回房间
		virtual void SendTableBaseProtocol(CharPtr & pChr);
	
	/*--------------------------- 状态机相关 ----------------------------------------------*/
	public:

		virtual void setChannelBattlePrepPlayer(void);					//准备
		virtual void setChannelBattleWillStart(void);					//即将开始
		virtual void setChannelBattleSendCards(void);					//发牌
		virtual void setChannelBattleCarryOn(void);						//游戏中
		virtual void setChannelBattleGetCards(void);					//摸牌
		virtual void setChannelBattleOutCards(void);					//出牌
		virtual void setChannelBattleGameCalc(void);					//结算
		virtual void setChannelBattleGameover(void);					//结束
		virtual void setChannelBattleShowMove(void);					//动画表现
		virtual void setChannelBattleSmaeIP(void);						//同IP检测
		virtual void setChannelBattleGetKing(void);						//抢地主
		virtual void setChannelBattleAddMult(void);						//加倍
		
		virtual HSMStateHandler	ChannelBattlePrepPlayerUpdate(void);	//准备Update
		virtual HSMStateHandler	ChannelBattleWillStartUpdate(void);		//即将开始Update
		virtual HSMStateHandler	ChannelBattleSendCardsUpdate(void);		//发牌Update
		virtual HSMStateHandler	ChannelBattleCarryOnUpdate(void);		//游戏中Update
		virtual HSMStateHandler	ChannelBattleGetCardsUpdate(void);		//摸牌Update
		virtual HSMStateHandler	ChannelBattleOutCardsUpdate(void);		//出牌Update
		virtual HSMStateHandler	ChannelBattleGameCalcUpdate(void);		//结算Update
		virtual HSMStateHandler	ChannelBattleShowMoveUpdate(void);		//动画表现Update
		virtual HSMStateHandler	ChannelBattleSmaeIPUpdate(void);		//同IP检测Update
		virtual HSMStateHandler	ChannelBattleGetKingUpdate(void);		//抢地主
		virtual HSMStateHandler	ChannelBattleAddMultUpdate(void);		//加倍
		
	public:
		//切换战场状态
		HSMStateHandler	ChangeChannelState(PKChannelRunStatus state);
		
		//战场状态相关
		WGSERVER_INLINE void setRunStatus(const PKChannelRunStatus & status){ m_run_status = status; }
		WGSERVER_INLINE PKChannelRunStatus GetRunStatus(){return m_run_status; }
	protected:
		//初始状态
		static HSMState battle_init(AIPuKeChannelBaseInterface *me, HSMEvent const *e);
		//准备
		static HSMState battle_prepplayer(AIPuKeChannelBaseInterface *me, HSMEvent const *e);
		//即将开始
		static HSMState battle_willstart(AIPuKeChannelBaseInterface *me, HSMEvent const *e);
		//发牌
		static HSMState battle_sendcards(AIPuKeChannelBaseInterface *me, HSMEvent const *e);
		//游戏中
		static HSMState battle_carryon(AIPuKeChannelBaseInterface *me, HSMEvent const *e);
		//摸牌
		static HSMState battle_getcards(AIPuKeChannelBaseInterface *me, HSMEvent const *e);
		//出牌
		static HSMState battle_outcards(AIPuKeChannelBaseInterface *me, HSMEvent const *e);
		//结算
		static HSMState battle_gamecalc(AIPuKeChannelBaseInterface *me, HSMEvent const *e);
		//结束
		static HSMState battle_gameover(AIPuKeChannelBaseInterface *me, HSMEvent const *e);
		//动画表现
		static HSMState battle_showmove(AIPuKeChannelBaseInterface *me, HSMEvent const *e);
		//同IP检测
		static HSMState battle_sameip(AIPuKeChannelBaseInterface *me, HSMEvent const *e);
		//抢地主
		static HSMState battle_getking(AIPuKeChannelBaseInterface *me, HSMEvent const *e);
		//加倍
		static HSMState battle_addmult(AIPuKeChannelBaseInterface *me, HSMEvent const *e);
		
	protected:
		PKChannelRunStatus m_run_status;				//战场当前运行状态
		PKChannelRunStatus m_go_run_status;				//战场下一个运行状态
		PKChannelRunStatus m_next_run_status;			//战场指定下个运行的状态
		
		uint32 m_status_endtimer;						// 状态机结束时间
		uint32 m_status_starttimer;						// 状态机开始时间
		
		PKGameLogic* PK_GameLogic;
		
	public:
		//得到扑克公共配置
		virtual uint32 GetPuKePublicData(const String & str);
		//初始话玩家列表
		virtual void InitPlayerSeatList();
		//检测玩家是否已在牌桌
		virtual PKBaseTablePlayer * GetTablePlayer(const uint32 & char_id);	
		//组合所有列表
		void GroupEverthingVVCard(const int & startindex, const int & grouplenth, const int & groupline, const int & veclenth, std::vector<std::vector<uint8 > > & groupcardlist, std::vector<std::vector<uint8 > > & grouplist,std::vector<uint8 > & result);
		void GroupEverthingVCard(const int & startindex, const int & grouplenth, const int & groupline, const int & veclenth, std::vector<uint8 > & groupcardlist, std::vector<std::vector<uint8 > > & grouplist,std::vector<uint8 > & result);
		//广播协议相关
		void BroadcastPacketCompareList(WorldPacket * packet, const uint32 & exceptId, std::vector<uint16> & comparelist);
		void Broadcast(WorldPacket * packet, uint32 exceptId = 255);
		
	public:
		//添加玩家进牌桌
		virtual bool AddPlayerJoinTable(CharPtr & pChr, const uint32 & PosID);
		//即将开始游戏状态机接口
		virtual void BattleWillStart(){};
		//设置庄家
		virtual uint32 SetBankerPos();
		//生成牌库
		virtual void OnCreateCards(std::vector<uint16> & cards);
		//洗牌
		virtual void ShuffleCards(const uint32 & loop);
		//倒牌
		virtual void CutCards();
		//添加下注记录
		virtual void AddPlayerChipinInfo(bool IsLook, const uint32 & ChipLoop, const uint32 & ChipMuch, const uint8 & ChipModel, PKBaseTablePlayer & player);
		//得到下一个发言人位置
		virtual uint32 GetNextSpeakID();
		//切换下一个发言人
		virtual uint32 ChangeNextSpeakingPos();
		//得到玩家可操作列表
		virtual bool GetPlayerCanOperatorMap(PKBaseTablePlayer * pTp,std::map<uint32, OperatorList > & OpMap);
		//得到玩家是否跟死
		virtual bool GetPlayerChipOverStatus(PKBaseTablePlayer * pTp);
		//得到玩家所有下注金额
		virtual uint32 GetPlayerAllChipMoney(PKBaseTablePlayer * pTp);
		//得到实际下注人数
		virtual uint32 GetPlayingValidPlayersNum();
		//得到可比牌列表
		virtual bool GetCanCompareList(PKBaseTablePlayer * pTp,std::vector<uint32> & vCompareList);
		//得到可下注列表
		virtual bool GetCanChipInList(PKBaseTablePlayer * pTp,std::vector<uint32> & vCompareList);
		//得到可加注列表
		virtual bool GetCanAddChipInList(PKBaseTablePlayer * pTp,std::vector<uint32> & vCompareList);
		//自动比牌
		virtual void CompareAllLivePlayerCards();
		//得到玩家Player
		virtual PKBaseTablePlayer * GetTablePlayerPosForPos(const uint32 & pos);
		virtual PKBaseTablePlayer * GetTablePlayerPosForChar(const uint32 & char_id);
		//下注、加注、跟注
		virtual uint8 ChipInAndAddAndFollow(const uint32 & char_id,const uint32 & coins,const uint32 & chipmodel);
		//检测下注金额得正确性
		virtual bool CheckChipInCoinsRight(PKBaseTablePlayer *pTp,const uint32 & coins);
		//检查玩家是否可以发言
		virtual uint8 CheckPlayerOperatorStatus(PKBaseTablePlayer *pTp);
		//检测牌局是否结束
		virtual bool CheckCenterBattleOver();
		//发送协议给玩家
		virtual void SendProtocolToPlayer(WorldPacket * packet, PKBaseTablePlayer * tp);
		virtual void SendProtocolToPlayer(WorldPacket * packet, PKBaseTablePlayer & tp);
		virtual void SendProtocolToPlayer(WorldPacket * packet, const uint8 & pos);
		//清除桌面按钮
		virtual void ClearTablePlayreOperatorButton();
		//结算分数
		virtual void CalcGameResult();
		//得到玩家位置
		virtual uint32 GetWinnerPos();
		//得到牌型名
		virtual String GetCardTypeStringName(const uint32 & cardtype,const uint8 & gamemodel);
		//动画状态机可重载函数
		virtual void ShowMoveModel(){};
		//自动弃牌
		virtual void AutoGiveUpCards();
		//玩家弃牌
		virtual bool GiveUpCards(const uint32 & charID);
		//玩家看牌
		virtual bool LookCards(const uint32 & charID);
		// 判断游戏结束
		virtual bool IsGameOver(){return true;};
		
		
		
		
	protected:
		uint32 m_u32ChannelAI;								//牌桌AI
		uint32 m_u32BankerPos;								//庄家位置
		uint32 m_u32UpBankerPos;							//上一轮庄家位置
		uint32 m_u32NextBankerPos;							//下一个庄家位置
		uint32 m_u32UpWinerPos;								//上一把赢家位置
		uint32 m_u32WinerPos;								//当前赢家位置
		uint32 m_u32LetSendCardInit;						//允许发送的初始牌数量
		uint32 m_u32LetSendCardMax;							//允许发送的最大牌数量
		uint32 m_u32ShowCardChipNow;						//牌桌当前看牌下注金额
		uint32 m_u32TableMaxChip;							//牌桌最大可下注金额（相当于看牌后最大金额）
		uint32 m_u32LoopNow;								//牌桌当前轮次
		uint32 m_u32LoopMax;								//牌桌最大轮次
		uint32 m_u32ChipLoopNow;							//牌桌当前下注轮次
		uint32 m_u32SpeakPosNow;							//牌桌当前发言人位置
		uint32 m_u32FirstSpeakPos;							//牌桌第一个发言人位置
		uint32 m_u32WinnerPos;								//牌桌赢家位置
		
		uint32 m_u32CheckSameIP;							//同IP检测
		uint32 m_u32CreateTime;								//牌桌创建时间
		uint32 m_u32GameModelXml;							//游戏模式
		double m_fTrax;										//抽水比例
		
		
		bool m_bIsSendCards;								//是否已发牌
		bool m_bIsCheckSameIP;								//同IP检测结束
		bool m_bIsAgreeLookCards;							//是否同意未比过牌的玩家看自己的牌
	
	public:
		std::map<uint32, stVotePlayer> m_mapVotePlayers;	// 投票玩家列表
		bool m_bVoting;										// 投票中
		uint32 m_nVoteOverTime;								// 投票结束时间
		uint32 m_nNextCheckTimeoutTime;						// 检查牌桌超时的时间
		uint32 m_nTimeoutTimer;								// 检查牌桌超时的时间
		uint8 m_nDissolveReson;								// 解散原因
		bool m_bDissolve;									// 牌桌是否为解散
		bool m_bGameOver;									// 游戏结束
		
	public:
	/* ---------------------------------游戏初始化Json数据------------------------------------------ */
		BattleTotalLog m_btLog;								// 组局数据记录
		uint32 m_nCB_id;									// 组局id
		uint32 m_nFzPid;									// 组局房主PID
		uint32 m_nBasePoint;								// 底分
		uint32 m_nLimitLoop;								// 限制局数
		uint32 m_nLimitRound;								// 限制圈数
		uint32 m_nExit_coins;								// 离场金币数
		uint32 m_nLimitTime;								// 限制时间
		uint32 m_nTopTimes;									// 封顶倍数
		uint32 m_nGameID;									// 组局游戏ID
		uint32 m_nGzid;										// 组局分区ID
		uint32 m_nMode;										// 游戏玩法ID
		uint32 m_nMaxPlayerNum;								// 最大游戏人数
		uint8 m_ui8PayMode;									// 付款模式
		bool  m_bOverTimeWait;								// 超时是否等待
		uint32 m_nStartPlayerNum;							// 开始游戏的人数
		bool m_bInitCenterData;								// 初始化组局数据
		String m_strPlayJsonData;							// 组局信息json字符串
		TownPtr m_Town;										// 牌桌对应房间
		Json::Value  m_GameLogData;							// 游戏回放记录
	
	public:
		std::vector<PKBaseTablePlayer> v_PKTablePlayers;				// 座位玩家列表
		std::vector<PKBaseTablePlayer> v_PKBaseTablePlayers;			// 座位玩家列表
		std::vector<PKBaseTablePlayer> v_PKWatchTablePlayers;			// 观战玩家列表
		
		std::vector<uint16> v_v16Cards;									//扑克容器
		
		std::vector<uint32> v_v32MangChipList;							//盲注列表
		std::vector<uint32> v_v32MingChipList;							//明注列表
		
	};
#endif // PKPUBLIC	

	typedef LockedQueue<ResourceProxy> ProxyLockQueue;
	typedef std::vector<ProxyLockQueue> ProxyLockVecQueue;
	/** 普通房间基类 **/
	class SERVER_DECL AITownBaseInterface : public AIInterface
	{
	public:
		void 	initialize(void);

	public:
		ADD_INTERFACE_FACTORY_FUNCTION(AITownBaseInterface);

		AITownBaseInterface(Resource * town);
		virtual ~AITownBaseInterface(void);

		virtual void Load(void);
		virtual void LoadXmlDate(void);
	public:
		/* 进入房间 */
		virtual bool 	JoinTown(CharPtr & pChr);
		/* 退出房间 */
		virtual bool	LeaveTown(CharPtr & pChr);
		//玩家准备
		virtual bool 	GameReady(CharPtr & pChr);
		//广播数据
		virtual void 	BroadcastPacket(WorldPacket * newP);
		//是否符合房间需求
		virtual bool 	CheckTownNeed(CharPtr & chr);
		//返回准备队列
		std::vector<ProxyLockVecQueue> & GetReadyList(void) { return m_vecReadyList; }
		//获取XML内容
		uint32 GetXMLData(const String & szName);
		//设置XML内容,未SaveDB
		void 	SetXMLData(const String & szName, const uint32 & val);
		// 增加计数
		void 	addRoomValve(const uint8 & roomlv);
		// 减少计数
		void 	reduceRoomValve(const uint8 & roomlv);
		// 获取计数
		uint32  getRoomValve(const uint8 & roomlv);
		// 获取当前人数
		uint32  GetPlayerNum(void) { return m_playernum.GetVal(); }

	public:
		Threading::AtomicCounter m_room_valve0;
		Threading::AtomicCounter m_room_valve1;
		Threading::AtomicCounter m_room_valve2;
		Threading::AtomicCounter m_room_valve3;
		Threading::AtomicCounter m_room_valve4;

	protected:
		std::vector<ProxyLockVecQueue> m_vecReadyList;
		Threading::AtomicCounter m_playernum;
		uint32 m_moneyQuota;		//最低限额
		uint32 m_nRoundLower;		//底分
		uint32 m_nRoundUpper;		//封顶
		// uint32 m_parentGame;		//隶属游戏
		uint32 m_need_lv;			//进入房间需求等级
		// TownTypeDef m_roomType;		//房间类型
		uint32 m_gamePlayer;		//游戏人数		
		// user_data
		XMLDataSet      m_xmlData;
	};

	typedef struct _creature_base_title_info_
	{
		uint32 id;
		uint32 create_time;
		_creature_base_title_info_(void)
		{
			id = 0;
			create_time = 0;
		}
	}TitleInfo;

	// 形象数据
	struct BodyData
	{
		uint32 id;
		uint32 endtime;
	};
	/******************************角色基类***************************************/
	class AICreatureBaseInterface : public AIInterface
	{
	protected:
		// vip信息锁
#define WGS_CHR_VIP_INNER_MUTEX_NAME chr_vip_inner_mutex
#define WGS_CHR_VIP_INNER_MUTEX mutable boost::mutex WGS_CHR_VIP_INNER_MUTEX_NAME;
#define WGS_CHR_VIP_INNER_LOCK		boost::lock_guard<boost::mutex> wgsChrVIPInnerMutexLock(WGS_CHR_VIP_INNER_MUTEX_NAME);
		WGS_CHR_VIP_INNER_MUTEX

#define WGS_CHARXML_READ_WRITE_MUTEX_NAME      xml_read_write_shared_mutex
#define WGS_CHARXML_READ_WRITE_MUTEX   mutable boost::shared_mutex WGS_CHARXML_READ_WRITE_MUTEX_NAME;
#define WGS_CHARXML_READ_LOCK             boost::shared_lock<boost::shared_mutex>  wgsXmlSharedMutexLock(WGS_CHARXML_READ_WRITE_MUTEX_NAME);
#define WGS_CHARXML_WRITE_LOCK 		boost::unique_lock<boost::shared_mutex>  wgsXmlWriteMutexLock(WGS_CHARXML_READ_WRITE_MUTEX_NAME); 
			WGS_CHARXML_READ_WRITE_MUTEX

#define WGS_CHR_FROZEN_INNER_MUTEX_NAME chr_frozen_inner_mutex
#define WGS_CHR_FROZEN_INNER_MUTEX mutable boost::mutex WGS_CHR_FROZEN_INNER_MUTEX_NAME;
#define WGS_CHR_FROZEN_INNER_LOCK		boost::lock_guard<boost::mutex> wgsChrChipInnerMutexLock(WGS_CHR_FROZEN_INNER_MUTEX_NAME);
			WGS_CHR_FROZEN_INNER_MUTEX
	public:
		ADD_INTERFACE_FACTORY_FUNCTION(AICreatureBaseInterface);

		AICreatureBaseInterface(Resource * pUnit);
		virtual ~AICreatureBaseInterface();
		//*********通用操作*********/
		// 领取奖励
		bool GainGift(const uint8 & type, const uint32 & data1);
		// 设置和获取房间ID
		WGSERVER_INLINE void SetTownNull(void) { m_townProxy.setNull(); }
		WGSERVER_INLINE void SetTown(ResourceProxy townProxy) { m_townProxy = townProxy; }
		WGSERVER_INLINE ResourcePtr GetTown(void) { return m_townProxy.getResourcePtr(); }
		// 设置和获取牌桌ID
		WGSERVER_INLINE void SetChannelNull(void) { m_channel.setNull(); }
		WGSERVER_INLINE void SetChannel(const ResourceProxy channelproxy) { m_channel = channelproxy; }
		WGSERVER_INLINE ResourcePtr GetChannelPtr(void) { return m_channel.getResourcePtr(); }
		// 设置和获取VIP房间桌号
		WGSERVER_INLINE uint32 GetVIPRoomID(void) { return m_nVipRoomID; }
		WGSERVER_INLINE void SetVIPRoomID(const uint32 handle) { m_nVipRoomID = handle; }
		// 是否清除自身
		virtual bool  	IsRemoveSelf(void) { return false; }
		// 玩家准备
		virtual bool	GameReady(const uint32 & sign_type = 0) { return true; }

		//*********乐码相关*********/	
		// 创建乐码并并发送到玩家邮件
		virtual bool CreateLECardToChar();
		//验证一张打折卡(卡状态)
		virtual uint8 CheckLECard(String & checkNode);

		//*********游戏成就*********/
		// 增加新成就
		virtual bool 	addTitle(const uint32 & tid, uint32 finishTime = 0);
		virtual uint32 	getTitlesList(std::list<TitleInfo> * plist);
		virtual bool 	HaveTitle(const uint32 & tid);

		//*********角色形象*********/
		virtual bool AddCreatureBody(const uint32 & bid, uint32 endtime = 0);
		virtual uint32 GetCreatureBodyList(std::list<BodyData> &plist);
		virtual void WriteCreatureBodyList(std::list<BodyData> &plist);
		virtual bool HaveCreatureBody(const uint32 & bid);
		//*********小游戏相关*********/
		// 运行公共小游戏
		virtual bool RunGame(const uint32 & key) { return false; }
		// 运行非公共小游戏
		virtual bool RunGame(SMGameData & gameinfo) { return false; }

		//*********勋章相关*********/
		// 添加VIP、勋章相关信息
		virtual void AddNewVIPInfo(VIPCard &vipCard);
		// 添加VIP勋章(覆盖数据)
		virtual void AddVipInfo(VIPCard &vipCard, const uint32 endTime);
		// 移除VIP勋章
		virtual void RemoveVipInfo();

		//*********XML数据操作*********/
		// 获取XML内容
		virtual uint32 GetXMLData(const String & szName);
		// 设置XML内容,未SaveDB
		virtual void 	SetXMLData(const String & szName, const uint32 & val, bool isSave = true);
		// 增加XMLDATA数值
		virtual void 	AddXMLValue(const String & szName, const uint32 & val, bool isSave = true);
		// 减少XML数值
		virtual bool 	ReduceXMLValue(const String & szName, const uint32 & val, bool isSave = true);
		
		// 获取String XML内容
		virtual String GetStringXMLData(const String & szName);
		// 设置String XML内容,未SaveDB
		virtual void 	SetStringXMLData(const String & szName, const String & val, bool isSave = true);
		
		// 获取int型XML内容
		virtual int 	GetIntXMLData(const String & szName);
		// 设置int型XML内容,未SaveDB
		virtual void 	SetIntXMLData(const String & szName, const int & val, bool isSave = true);
		
		// 增加int型XMLDATA数值
		virtual void 	AddIntXMLValue(const String & szName, const int & val, bool isSave = true);
		virtual void 	ReduceIntXMLValue(const String & szName, const int & val, bool isSave = true);

		//*********二级密码*********/
		// 设置二级密码验证状态
		virtual WGSERVER_INLINE void SetValidated(bool bValidate) { m_bValidated = bValidate; };
		// 得到二级密码验证状态
		virtual WGSERVER_INLINE bool GetValidated()const { return m_bValidated; };
		// 重置
		// virtual void Reset();
		// 获取二级密码验证结果
		virtual uint8 ValidateSecondPassword(const String &Pwd);

		/******** 冻结物品相关 *******/
		// 获取冻结金额
		virtual const uint32 GetFrozenCapital(const uint32 modelId);
		// 添加冻结
		virtual bool AddFrozenCapital(const uint32 modelId, const uint32 value);
		// 解除冻结(0:解冻全部)
		virtual void ReleaseFrozenCapital(const uint32 modelId, const uint32 value = 0);

		/************** 现在奖励相关 **************/
		// 初始通用在线奖励数据
		virtual bool InitCommonOnlineGiftData();
		// 更新通用在线列表数据
		virtual void UpdateCommonOnlineGiftData(bool bOffline = false);
		// 发送通用在线奖励
		virtual void SendCommonOnlineGift();
		// 领取在线奖励
		virtual bool GetCommonOnlineGiftBounty(const uint32 & id);
		
		// 设置获取玩家想要坐入座位的数据
		virtual void SetWantSitPos(const uint8 & pos){ m_nWantSitPos = pos; }
		virtual uint8 GetWantSitPos(){ return  m_nWantSitPos; }
		
	protected:
		// 房间ID
		ResourceProxy m_townProxy;
		// 牌桌ID
		ResourceProxy m_channel;

		// 是否已验证二级密码
		bool m_bValidated;
		// 二级密码连续出错次数
		uint32 m_ErrorCount;
		// 二级密码锁定时间
		uint32 m_LockTime;

		// 乐码验证连续出错次数
		uint32 m_LeErrorCount;
		// 乐码验证锁定时间
		uint32 m_LeLockTime;

		// VIP房间ID
		uint32 m_nVipRoomID;

		// 冻结金额
		std::map<uint32, uint32> m_mapFrozen;
		
		uint8 m_nWantSitPos;					// 想要坐下的位置
	};

	/******************************效果基类*******************************/
	class SERVER_DECL AIEffectInterface : public AIInterface
	{
	public:

		enum EffectRangeType
		{
			EffectRange_None = 0,
			EffectRange_Round,		//圆形
			EffectRange_Rectangle,	//矩形
			EffectRange_Criss		//十字形
		};

		enum EffectStatusType
		{
			EffectStatus_None = 0,
			EffectStatus_Active,
		};

		enum EffectTargetType
		{
			EffectTargetType_None = 0,
			EffectTargetType_Alone = 1,	//单独对象
			EffectTargetType_SrcTagToDestTag = 2,	//源对象到目标对象
			EffectTargetType_SrcTagToDestPos = 3,	//源对象到目标点
			EffectTargetType_SrcPosToDestPos = 4,	//源点到目标点
			EffectTargetType_RangeAllTag = 5,	//范围所有对象
			EffectTargetType_RangeFriendTag = 6,	//范围己方对象
			EffectTargetType_RangeEnemyTag = 7,	//范围敌方对象
			EffectTargetType_AllFriend = 8,		//己方全部对象
			EffectTargetType_AllEnemy = 9,		//敌方全部对象
		};

	public:
		ADD_INTERFACE_FACTORY_FUNCTION(AIEffectInterface);

		AIEffectInterface(Resource * pUnit);
		virtual ~AIEffectInterface() {};

	public:
		void 	init(void);
		void 	Load(void);
		void 	Unload(void);
		void 	Update(const uint32 & p_time);
		uint8 	ActiveEffect(ResourceEvent * event, const uint32 & exp_time = 0);

		////////////效果操作////////////		
		uint8 	HandleEvent(ResourceEvent * event);
		//更新剩余消耗时间
		void 	UpdateLeaveDurationTimer(void);
		//获取效果作用矩形
		WGSERVER_INLINE const Rect GetEffectRect() { return m_effectRect; }
		//设置特效间隔(ms)
		WGSERVER_INLINE void 	SetEffectInterval(const uint32 & sleep) { m_interval_time = sleep; }
		WGSERVER_INLINE const uint32 & 	GetEffectInterval(void) { return m_interval_time; }
		WGSERVER_INLINE const uint32 &  GetEffectDuration(void) { return m_duration_time; }
		//获取冷却时间
		WGSERVER_INLINE const uint32 &  GetCongealTime(void) { return m_congeal_time; }
		//是否冷却
		WGSERVER_INLINE bool IsCongeal(void) { return m_congeal_last_time; }
		//进入冷却
		void StartCongeal(const uint32 & congeal_timer);
		//效果状态标识
		WGSERVER_INLINE const EffectStatusType & GetEffectStatus(void) { return m_effectStatus; }
		////////获取效果相关/////////
		WGSERVER_INLINE ResourcePtr GetEffectOwner(void) { return m_ownerProxy.getResourcePtr(); }
		WGSERVER_INLINE ResourcePtr GetEffectSource(void) { return m_srcProxy.getResourcePtr(); }
		WGSERVER_INLINE ResourcePtr GetEffectTarget(void) { return m_tagProxy.getResourcePtr(); }
		//获取效果模式号
		WGSERVER_INLINE const uint32 & GetModelID(void) { return m_model_id; }
		//获取效果循环次数
		WGSERVER_INLINE const uint32 & GetLoop(void) { return m_triggerMax; }

		//获取效果目的点
		WGSERVER_INLINE const Vector3 & GetDestPosition(void) { return m_dest_pos; }
		//获取效果源点
		WGSERVER_INLINE const Vector3 & GetSourcePosition(void) { return m_src_pos; }

		//修改效果结束时间, 单位：ms
		void SetEndTimer(const int32 & time);

		//重新执行
		void ResetEffectLoop();

	protected:
		void 	UpdateEffect(const uint32 & p_time);

	public:
		uint32 		m_effect1;		//附加数据
		uint32 		m_effect2;
		uint32 		m_effect3;
		uint32 		m_effect4;
		uint32 		m_effect5;
		uint32 		m_effect6;
		uint32 		m_effect7;
		uint32 		m_sub_effect1;	//效果的子效果
		uint32 		m_sub_effect2;
		uint8		m_effectTargetType;	//效果作用对象类型
		XMLDataSet      m_xmlData;
	protected:
		EffectRangeType m_effectRangeType;	//效果作用范围类型

		EffectStatusType m_effectStatus;
		ResourceProxy 	m_ownerProxy;	//效果拥有者
		ResourceProxy	m_srcProxy;		//效果源
		ResourceProxy	m_tagProxy;		//效果目标
		uint32 	m_model_id;

		// uint32 	m_triggerSleep;		//触发延时
		uint32 	m_triggerMax;		//触发最大次数
		uint32 	m_currTriggerCount;	//触发计数
		uint32 	m_range_x;	//效果范围X(半径)
		uint32 	m_range_y;	//效果范围Y(矩形或十字型)

		// uint32  m_exp_interval
		uint32 	m_interval_time;	//间隔时间
		uint32  m_duration_time;	//生存时间
		uint32  m_leave_duration_time;	//剩余生存时间

		uint32  m_exp_interval;		//间隔消耗时间
		uint32  m_exp_duration_time;//生存消耗时间

		uint32  m_congeal_time;		//冷却间隔时间
		uint32  m_congeal_start_time;	//冷却开始时间
		uint32  m_congeal_last_time;//冷却消耗时间

		uint32  m_start_time;

		Rect 	m_effectRect;
		Vector3 m_src_pos;		//源点
		Vector3 m_dest_pos;		//目的点

		Threading::AtomicBoolean 	m_isRemoved;

	};

	/******************************任务基类*******************************/
	class SERVER_DECL AIMissionInterface : public AIInterface
	{
	public:
		ADD_INTERFACE_FACTORY_FUNCTION(AIMissionInterface);

		AIMissionInterface(Resource * pUnit);
		virtual ~AIMissionInterface();

		void 		Load(void);
		WGSERVER_INLINE ResourcePtr GetMissOwner(void) { return m_ownerProxy.getResourcePtr(); }
		WGSERVER_INLINE ResourcePtr GetMissSrcTarget(void) { return m_sourceProxy.getResourcePtr(); }
		WGSERVER_INLINE ResourcePtr GetMissTargetTarget(void) { return m_targetProxy.getResourcePtr(); }

		uint8	HandleEvent(ResourceEvent * event);
	protected:
		ResourceProxy m_ownerProxy;
		ResourceProxy m_sourceProxy;
		ResourceProxy m_targetProxy;

	};
}




#endif
